import { type FunctionalComponent, h, ref } from 'vue'
import { NFormBuilder } from '@/components/NFormBuilder/index.ts'

export function useFormBuilder(props: any) {
  const formInstance = ref()
  const FormBuilder = ((_, { slots }) =>
    h(
      NFormBuilder,
      {
        ...props,
        ref: formInstance,
      },
      slots,
    )) as FunctionalComponent

  return {
    FormBuilder,
    validate() {
      return formInstance.value.validate()
    },
  }
}
